<?php
/**
 * If you are not authorized to modify this file, do NOT touch it.
 * @file authcode.php
 * @author SkyWorld
 * @date 2010-9-17
 * @description This script will output an authcode picture and create an session with authcode
 */

include '../../inc/common.inc.php';
$with=90;$height=30;$length=5;
//create a picture with the right size
$im	=	imagecreatetruecolor( $with, $height ) or die ( "Cannot Initialize new GD image stream" );

//set three colors

$green	=	imagecolorallocate( $im, rand(60,70), 197, 102 );
$white	=	imagecolorallocate( $im, 245, 255, 255 );
$blue	=	imagecolorallocate( $im, 62, 80, 115 );

//get the absolute path of font, for portability issues
$font_path = SKY_DLL.'font/SEGOESCB.TTF';


// file the picture with color
imagefill( $im, 0, 0, $white );

// create a random number
$authnum='';
for($i=0;$i<$length;$i++){
	$authnum.=rand(1,9);
}
$_SESSION['authcode']	=	$authnum;

//paint the random number to the picture
imagettftext( $im, 18, rand(-5,5), 0, 22, $green, $font_path, $_SESSION['authcode'] );
//imagestring($im, , 10,10, $authnum, $green);
//add some disturb dots
for( $i = 0; $i < 300; $i++ )
{
	$randcolor	=	imagecolorallocate( $im, rand( 0, 255 ), rand( 0, 255 ), rand( 0, 255 ) );
	imagesetpixel( $im, rand() % 90 , rand() % 30 , $randcolor );
}

//add one disturb line
for($i=0;$i<2;$i++){
	$randcolor	=	imagecolorallocate( $im, rand( 0, 255 ), rand( 0, 255 ), rand( 0, 255 ) );
	imageline($im,rand(0,20),rand(0,30),90,30,$randcolor);
}

//output the authcode picture in gif type
header( "Content-type: image/gif" );
imagegif( $im );
imagedestroy( $im );		// destory the authcode picture
?>